#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> countingSort(const vector<int>& v,int min,int max)
{
    vector<int> count(max-min+1,0);
    vector<int> sorted;
    for(int i=0;i<v.size();i++)
    {
        count[v[i]-min]++;
    }
    for(int i=0;i<count.size();i++)
    {
        while(count[i]>0)
        {
            sorted.push_back(i+min);
            count[i]--;
        }
    }
    return sorted;
}

int main()
{
    cout<<"Enter the minimum and maximum values:"<<endl;
    int min,max;
    cin>>min;
    cin>>max;
    cout<<"Enter the numbers:"<<endl;
    vector<int> v;
    int n;
    while(n!=-1)
    {
        cin>>n;
        v.push_back(n);
    }
    v.pop_back();
    v=countingSort(v,min,max);
    cout<<"Sorted array:"<<endl;
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}

